//author:dhclly
// 基础类型 · TypeScript中文网 · TypeScript——JavaScript的超集
// https://www.tslang.cn/docs/handbook/basic-types.html
var o = console.log;
//--boolean
var boolType = false;
o("boolType:", boolType);
//--number
var numberType = 10;
o("numberType:", numberType);
var numberTypeHex = 0xf;
o("numberTypeHex:", numberTypeHex);
var numberTypeBinary = 10;
o("numberTypeBinary:", numberTypeBinary);
var numberTypeOct = 484;
o("numberTypeOct:", numberTypeOct);
//--string
var myname = "Gene"; //不能命名为name，会报错，和window.name定义冲突
var age = 37;
var sentence = "Hello, my name is " + myname + ". I'll be " + (age + 1) + " years old next month.";
o(sentence);
//--tuple 复合类型
// Declare a tuple type
var x;
// Initialize it
x = ["hello", 10]; // OK
o(x[0], x[1]);
// Initialize it incorrectly
//x = [10, 'hello']; // Error
//o(x[0],x[1]);
// 当访问一个越界的元素，会使用联合类型替代(新版本不能这么玩，只能用定义好的)
x[0] = "world"; // OK, 字符串可以赋值给(string | number)类型
o(x[0]);
o(x[1].toString());
//-- enum 枚举
var Color;
(function (Color) {
    Color[Color["Red"] = 1] = "Red";
    Color[Color["Green"] = 2] = "Green";
    Color[Color["Blue"] = 3] = "Blue";
})(Color || (Color = {}));
var green = Color.Green;
var colorName = Color[2];
o("clolor ", green);
o("color name ", colorName);
//-- any
var notSure = 4;
notSure = "maybe a string instead";
o(notSure);
notSure = false; // okay, definitely a boolean
o(notSure);
notSure = {};
notSure.ifItExists = function () { };
notSure.ifItExists(); // okay, ifItExists might exist at runtime
o('okay, ifItExists might exist at runtime');
notSure = 1.0;
notSure.toFixed(); // okay, toFixed exists (but the compiler doesn't check)
o('okay, toFixed exists \(but the compiler doesn\'t check\)');
var prettySure = 4;
//prettySure.toFixed(); // Error: Property 'toFixed' doesn't exist on type 'Object'.
var list = [1, true, "free"];
list[1] = 100;
//-- void
function warnUser() {
    o("This is my warning message");
}
var unusable = undefined;
var unusable2 = null;
//--Null 和 Undefined
// Not much else we can assign to these variables!
var u = undefined;
var n = null;
//--Never
// 返回never的函数必须存在无法达到的终点
function n_error(message) {
    throw new Error(message);
}
// 推断的返回值类型为never
function n_fail() {
    return n_error("Something failed");
}
// 返回never的函数必须存在无法达到的终点
function n_infiniteLoop() {
    while (true) {
    }
}
// create({ prop: 0 }); // OK
// create(null); // OK
// create(42); // Error
// create("string"); // Error
// create(false); // Error
// create(undefined); // Error
//-- type assert 类型转换
var someValue = "this is a string";
o(someValue);
var strLength = someValue.length;
o(strLength);
var someValue2 = "this is a string";
o(someValue2);
var strLength2 = someValue2.length;
o(strLength2);
